Method and apparatus for processing video signal

ABSTRACT

A method for decoding a video according to the present invention may comprise: determining an intra prediction mode of a current block, determining, based on the intra prediction mode, a first reference sample of a prediction target sample included in the current block, generating a first prediction sample for the prediction target sample using the first reference sample, and generating a second prediction sample for the prediction target sample using the first prediction sample and a second reference sample located at a position different from the first reference sample.

TECHNICAL FIELD

The present invention relates to a method and an apparatus forprocessing video signal.

BACKGROUND ART

Recently, demands for high-resolution and high-quality images such ashigh definition (HD) images and ultra-high definition (UHD) images haveincreased in various application fields. However, higher resolution andquality image data has increasing amounts of data in comparison withconventional image data. Therefore, when transmitting image data byusing a medium such as conventional wired and wireless broadbandnetworks, or when storing image data by using a conventional storagemedium, costs of transmitting and storing increase. In order to solvethese problems occurring with an increase in resolution and quality ofimage data, high-efficiency image encoding/decoding techniques may beutilized.

Image compression technology includes various techniques, including: aninter-prediction technique of predicting a pixel value included in acurrent picture from a previous or subsequent picture of the currentpicture; an intra-prediction technique of predicting a pixel valueincluded in a current picture by using pixel information in the currentpicture; an entropy encoding technique of assigning a short code to avalue with a high appearance frequency and assigning a long code to avalue with a low appearance frequency; etc. Image data may beeffectively compressed by using such image compression technology, andmay be transmitted or stored.

In the meantime, with demands for high-resolution images, demands forstereographic image content, which is a new image service, have alsoincreased. A video compression technique for effectively providingstereographic image content with high resolution and ultra-highresolution is being discussed.

DISCLOSURE Technical Problem

An object of the present invention is to provide a method and anapparatus for efficiently performing intra-prediction for anencoding/decoding target block in encoding/decoding a video signal.

An object of the present invention is to provide a method and anapparatus for performing intra prediction through a weighted predictionusing a plurality of reference samples in encoding/decoding a videosignal.

The technical objects to be achieved by the present invention are notlimited to the above-mentioned technical problems. And, other technicalproblems that are not mentioned will be apparently understood to thoseskilled in the art from the following description.

Technical Solution

A method and an apparatus for decoding a video signal according to thepresent invention may determine an intra prediction mode of a currentblock, determine, based on the intra prediction mode, a first referencesample of a prediction target sample included in the current block,generate a first prediction sample for the prediction target sampleusing the first reference sample, and generate a second predictionsample for the prediction target sample using the first predictionsample and a second reference sample located at a position differentfrom the first reference sample.

A method and an apparatus for encoding a video signal according to thepresent invention may determine an intra prediction mode of a currentblock, determine, based on the intra prediction mode, a first referencesample of a prediction target sample included in the current block,generate a first prediction sample for the prediction target sampleusing the first reference sample, and generate a second predictionsample for the prediction target sample using the first predictionsample and a second reference sample located at a position differentfrom the first reference sample.

In the method and the apparatus for encoding/decoding a video signalaccording to the present invention, the second reference sample maycomprise at least one of a reference sample lying on a same horizontalline as the prediction target sample or a reference sample lying on asame vertical line as the prediction target sample.

In the method and the apparatus for encoding/decoding a video signalaccording to the present invention, each of the first reference sampleand the second reference sample may be adjacent to different boundariesof the current block.

In the method and the apparatus for encoding/decoding a video signalaccording to the present invention, a position of the second referencesample may be determined based on a directionality of the intraprediction mode.

In the method and the apparatus for encoding/decoding a video signalaccording to the present invention, the second prediction sample may begenerated based on a weighted sum of the first prediction sample and thesecond reference sample.

In the method and the apparatus for encoding/decoding a video signalaccording to the present invention, weights applied to each of the firstprediction sample and the second reference sample may be determinedbased on a position of the first reference sample and a position of thesecond reference sample.

In the method and the apparatus for encoding/decoding a video signalaccording to the present invention, whether to generate the secondprediction sample may be determined according to a directionality of theintra prediction mode.

The features briefly summarized above for the present invention are onlyillustrative aspects of the detailed description of the invention thatfollows, but do not limit the scope of the invention.

Advantageous Effects

According to the present invention, intra-prediction may be performedefficiently for an encoding/decoding target block.

According to the present invention, intra prediction can be performedbased on a weighted prediction using a plurality of reference samples.

The effects obtainable by the present invention are not limited to theabove-mentioned effects, and other effects not mentioned can be clearlyunderstood by those skilled in the art from the description below.

DESCRIPTION OF DRAWINGS

FIG. 1 is a block diagram illustrating a device for encoding a videoaccording to an embodiment of the present invention.

FIG. 2 is a block diagram illustrating a device for decoding a videoaccording to an embodiment of the present invention.

FIG. 3 is a diagram illustrating an example of hierarchicallypartitioning a coding block based on a tree structure according to anembodiment of the present invention.

FIG. 4 is a diagram illustrating a partition type in which binarytree-based partitioning is allowed according to an embodiment of thepresent invention.

FIGS. 5A and 5B are diagrams illustrating an example in which only abinary tree-based partition of a pre-determined type is allowedaccording to an embodiment of the present invention.

FIG. 6 is a diagram for explaining an example in which informationrelated to the allowable number of binary tree partitioning isencoded/decoded, according to an embodiment to which the presentinvention is applied.

FIG. 7 is a diagram illustrating a partition mode applicable to a codingblock according to an embodiment of the present invention.

FIG. 8 is a diagram illustrating types of pre-defined intra predictionmodes for a device for encoding/decoding a video according to anembodiment of the present invention.

FIG. 9 is a diagram illustrating a kind of extended intra predictionmodes according to an embodiment of the present invention.

FIG. 10 is a flowchart briefly illustrating an intra prediction methodaccording to an embodiment of the present invention.

FIG. 11 is a diagram illustrating a method of correcting a predictionsample of a current block based on differential information ofneighboring samples according to an embodiment of the present invention.

FIGS. 12 and 13 are diagrams illustrating a method of correcting aprediction sample based on a predetermined correction filter accordingto an embodiment of the present invention.

FIG. 14 shows a range of reference samples for intra predictionaccording to an embodiment to which the present invention is applied.

FIGS. 15 to 17 illustrate an example of filtering on reference samplesaccording to an embodiment of the present invention.

FIGS. 18A and 18B are diagrams showing an example of deriving a rightreference sample or a bottom reference sample using a plurality ofreference samples.

FIGS. 19 and 20 are diagrams for explaining a determination of a rightreference sample and a bottom reference sample for a non-square block,according to an embodiment of the present invention.

FIGS. 21 and 22 are diagrams illustrating a one-dimensional referencesample group in which reference samples are rearranged in a line.

FIG. 23 is a diagram for explaining a distance between a first referencesample and a prediction target sample.

FIGS. 24 and 25 are diagrams showing positions of a first referencesample and a second reference sample.

FIG. 26 is a diagram showing positions of a first reference sample and asecond reference sample.

FIG. 27 is a flowchart illustrating processes of obtaining a residualsample according to an embodiment to which the present invention isapplied.

MODE FOR INVENTION

A variety of modifications may be made to the present invention andthere are various embodiments of the present invention, examples ofwhich will now be provided with reference to drawings and described indetail. However, the present invention is not limited thereto, and theexemplary embodiments can be construed as including all modifications,equivalents, or substitutes in a technical concept and a technical scopeof the present invention. The similar reference numerals refer to thesimilar element in described the drawings.

Terms used in the specification, ‘first’, ‘second’, etc. can be used todescribe various components, but the components are not to be construedas being limited to the terms. The terms are only used to differentiateone component from other components. For example, the ‘first’ componentmay be named the ‘second’ component without departing from the scope ofthe present invention, and the ‘second’ component may also be similarlynamed the ‘first’ component. The term ‘and/or’ includes a combination ofa plurality of items or any one of a plurality of terms.

It will be understood that when an element is simply referred to asbeing ‘connected to’ or ‘coupled to’ another element without being‘directly connected to’ or ‘directly coupled to’ another element in thepresent description, it may be ‘directly connected to’ or ‘directlycoupled to’ another element or be connected to or coupled to anotherelement, having the other element intervening therebetween. In contrast,it should be understood that when an element is referred to as being“directly coupled” or “directly connected” to another element, there areno intervening elements present.

The terms used in the present specification are merely used to describeparticular embodiments, and are not intended to limit the presentinvention. An expression used in the singular encompasses the expressionof the plural, unless it has a clearly different meaning in the context.In the present specification, it is to be understood that terms such as“including”, “having”, etc. are intended to indicate the existence ofthe features, numbers, steps, actions, elements, parts, or combinationsthereof disclosed in the specification, and are not intended to precludethe possibility that one or more other features, numbers, steps,actions, elements, parts, or combinations thereof may exist or may beadded.

Hereinafter, preferred embodiments of the present invention will bedescribed in detail with reference to the accompanying drawings.Hereinafter, the same constituent elements in the drawings are denotedby the same reference numerals, and a repeated description of the sameelements will be omitted.

FIG. 1 is a block diagram illustrating a device for encoding a videoaccording to an embodiment of the present invention.

Referring to FIG. 1, the device 100 for encoding a video may include: apicture partitioning module 110, prediction modules 120 and 125, atransform module 130, a quantization module 135, a rearrangement module160, an entropy encoding module 165, an inverse quantization module 140,an inverse transform module 145, a filter module 150, and a memory 155.

The constitutional parts shown in FIG. 1 are independently shown so asto represent characteristic functions different from each other in thedevice for encoding a video. Thus, it does not mean that eachconstitutional part is constituted in a constitutional unit of separatedhardware or software. In other words, each constitutional part includeseach of enumerated constitutional parts for convenience. Thus, at leasttwo constitutional parts of each constitutional part may be combined toform one constitutional part or one constitutional part may be dividedinto a plurality of constitutional parts to perform each function. Theembodiment where each constitutional part is combined and the embodimentwhere one constitutional part is divided are also included in the scopeof the present invention, if not departing from the essence of thepresent invention.

Also, some of constituents may not be indispensable constituentsperforming essential functions of the present invention but be selectiveconstituents improving only performance thereof. The present inventionmay be implemented by including only the indispensable constitutionalparts for implementing the essence of the present invention except theconstituents used in improving performance. The structure including onlythe indispensable constituents except the selective constituents used inimproving only performance is also included in the scope of the presentinvention.

The picture partitioning module 110 may partition an input picture intoone or more processing units. Here, the processing unit may be aprediction unit (PU), a transform unit (TU), or a coding unit (CU). Thepicture partitioning module 110 may partition one picture intocombinations of multiple coding units, prediction units, and transformunits, and may encode a picture by selecting one combination of codingunits, prediction units, and transform units with a predeterminedcriterion (e.g., cost function).

For example, one picture may be partitioned into multiple coding units.A recursive tree structure, such as a quad tree structure, may be usedto partition a picture into coding units. A coding unit which ispartitioned into other coding units with one picture or a largest codingunit as a root may be partitioned with child nodes corresponding to thenumber of partitioned coding units. A coding unit which is no longerpartitioned by a predetermined limitation serves as a leaf node. Thatis, when it is assumed that only square partitioning is possible for onecoding unit, one coding unit may be partitioned into four other codingunits at most.

Hereinafter, in the embodiment of the present invention, the coding unitmay mean a unit performing encoding, or a unit performing decoding.

A prediction unit may be one of partitions partitioned into a square ora rectangular shape having the same size in a single coding unit, or aprediction unit may be one of partitions partitioned so as to have adifferent shape/size in a single coding unit.

When a prediction unit subjected to intra prediction is generated basedon a coding unit and the coding unit is not the smallest coding unit,intra prediction may be performed without partitioning the coding unitinto multiple prediction units N×N.

The prediction modules 120 and 125 may include an inter predictionmodule 120 performing inter prediction and an intra prediction module125 performing intra prediction. Whether to perform inter prediction orintra prediction for the prediction unit may be determined, and detailedinformation (e.g., an intra prediction mode, a motion vector, areference picture, etc.) according to each prediction method may bedetermined. Here, the processing unit subjected to prediction may bedifferent from the processing unit for which the prediction method anddetailed content is determined. For example, the prediction method, theprediction mode, etc. may be determined by the prediction unit, andprediction may be performed by the transform unit. A residual value(residual block) between the generated prediction block and an originalblock may be input to the transform module 130. Also, prediction modeinformation, motion vector information, etc. used for prediction may beencoded with the residual value by the entropy encoding module 165 andmay be transmitted to a device for decoding a video. When a particularencoding mode is used, it is possible to transmit to a device fordecoding video by encoding the original block as it is withoutgenerating the prediction block through the prediction modules 120 and125.

The inter prediction module 120 may predict the prediction unit based oninformation of at least one of a previous picture or a subsequentpicture of the current picture, or may predict the prediction unit basedon information of some encoded regions in the current picture, in somecases. The inter prediction module 120 may include a reference pictureinterpolation module, a motion prediction module, and a motioncompensation module.

The reference picture interpolation module may receive reference pictureinformation from the memory 155 and may generate pixel information of aninteger pixel or less then the integer pixel from the reference picture.In the case of luma pixels, an 8-tap DCT-based interpolation filterhaving different filter coefficients may be used to generate pixelinformation of an integer pixel or less than an integer pixel in unitsof a ¼ pixel. In the case of chroma signals, a 4-tap DCT-basedinterpolation filter having different filter coefficient may be used togenerate pixel information of an integer pixel or less than an integerpixel in units of a ⅛ pixel.

The motion prediction module may perform motion prediction based on thereference picture interpolated by the reference picture interpolationmodule. As methods for calculating a motion vector, various methods,such as a full search-based block matching algorithm (FBMA), a threestep search (TSS), a new three-step search algorithm (NTS), etc., may beused. The motion vector may have a motion vector value in units of a ½pixel or a ¼ pixel based on an interpolated pixel. The motion predictionmodule may predict a current prediction unit by changing the motionprediction method. As motion prediction methods, various methods, suchas a skip method, a merge method, an AMVP (Advanced Motion VectorPrediction) method, an intra block copy method, etc., may be used.

The intra prediction module 125 may generate a prediction unit based onreference pixel information neighboring to a current block which ispixel information in the current picture. When the neighboring block ofthe current prediction unit is a block subjected to inter prediction andthus a reference pixel is a pixel subjected to inter prediction, thereference pixel included in the block subjected to inter prediction maybe replaced with reference pixel information of a neighboring blocksubjected to intra prediction. That is, when a reference pixel is notavailable, at least one reference pixel of available reference pixelsmay be used instead of unavailable reference pixel information.

Prediction modes in intra prediction may include a directionalprediction mode using reference pixel information depending on aprediction direction and a non-directional prediction mode not usingdirectional information in performing prediction. A mode for predictingluma information may be different from a mode for predicting chromainformation, and in order to predict the chroma information, intraprediction mode information used to predict luma information orpredicted luma signal information may be utilized.

In performing intra prediction, when the size of the prediction unit isthe same as the size of the transform unit, intra prediction may beperformed on the prediction unit based on pixels positioned at the left,the top left, and the top of the prediction unit. However, in performingintra prediction, when the size of the prediction unit is different fromthe size of the transform unit, intra prediction may be performed usinga reference pixel based on the transform unit. Also, intra predictionusing N×N partitioning may be used for only the smallest coding unit.

In the intra prediction method, a prediction block may be generatedafter applying an AIS (Adaptive Intra Smoothing) filter to a referencepixel depending on the prediction modes. The type of the AIS filterapplied to the reference pixel may vary. In order to perform the intraprediction method, an intra prediction mode of the current predictionunit may be predicted from the intra prediction mode of the predictionunit neighboring to the current prediction unit. In prediction of theprediction mode of the current prediction unit by using mode informationpredicted from the neighboring prediction unit, when the intraprediction mode of the current prediction unit is the same as the intraprediction mode of the neighboring prediction unit, informationindicating that the prediction modes of the current prediction unit andthe neighboring prediction unit are equal to each other may betransmitted using predetermined flag information. When the predictionmode of the current prediction unit is different from the predictionmode of the neighboring prediction unit, entropy encoding may beperformed to encode prediction mode information of the current block.

Also, a residual block including information on a residual value whichis a different between the prediction unit subjected to prediction andthe original block of the prediction unit may be generated based onprediction units generated by the prediction modules 120 and 125. Thegenerated residual block may be input to the transform module 130.

The transform module 130 may transform the residual block including theinformation on the residual value between the original block and theprediction unit generated by the prediction modules 120 and 125 by usinga transform method, such as discrete cosine transform (DCT), discretesine transform (DST), and KLT. Whether to apply DCT, DST, or KLT inorder to transform the residual block may be determined based on intraprediction mode information of the prediction unit used to generate theresidual block.

The quantization module 135 may quantize values transformed to afrequency domain by the transform module 130. Quantization coefficientsmay vary depending on the block or importance of a picture. The valuescalculated by the quantization module 135 may be provided to the inversequantization module 140 and the rearrangement module 160.

The rearrangement module 160 may rearrange coefficients of quantizedresidual values.

The rearrangement module 160 may change a coefficient in the form of atwo-dimensional block into a coefficient in the form of aone-dimensional vector through a coefficient scanning method. Forexample, the rearrangement module 160 may scan from a DC coefficient toa coefficient in a high frequency domain using a zigzag scanning methodso as to change the coefficients to be in the form of one-dimensionalvectors. Depending on the size of the transform unit and the intraprediction mode, vertical direction scanning where coefficients in theform of two-dimensional blocks are scanned in the column direction orhorizontal direction scanning where coefficients in the form oftwo-dimensional blocks are scanned in the row direction may be usedinstead of zigzag scanning. That is, which scanning method among zigzagscanning, vertical direction scanning, and horizontal direction scanningis used may be determined depending on the size of the transform unitand the intra prediction mode.

The entropy encoding module 165 may perform entropy encoding based onthe values calculated by the rearrangement module 160. Entropy encodingmay use various encoding methods, for example, exponential Golombcoding, context-adaptive variable length coding (CAVLC), andcontext-adaptive binary arithmetic coding (CABAC).

The entropy encoding module 165 may encode a variety of information,such as residual value coefficient information and block typeinformation of the coding unit, prediction mode information, partitionunit information, prediction unit information, transform unitinformation, motion vector information, reference frame information,block interpolation information, filtering information, etc. from therearrangement module 160 and the prediction modules 120 and 125.

The entropy encoding module 165 may entropy encode the coefficients ofthe coding unit input from the rearrangement module 160.

The inverse quantization module 140 may inversely quantize the valuesquantized by the quantization module 135 and the inverse transformmodule 145 may inversely transform the values transformed by thetransform module 130. The residual value generated by the inversequantization module 140 and the inverse transform module 145 may becombined with the prediction unit predicted by a motion estimationmodule, a motion compensation module, and the intra prediction module ofthe prediction modules 120 and 125 such that a reconstructed block canbe generated.

The filter module 150 may include at least one of a deblocking filter,an offset correction unit, and an adaptive loop filter (ALF).

The deblocking filter may remove block distortion that occurs due toboundaries between the blocks in the reconstructed picture. In order todetermine whether to perform deblocking, the pixels included in severalrows or columns in the block may be a basis of determining whether toapply the deblocking filter to the current block. When the deblockingfilter is applied to the block, a strong filter or a weak filter may beapplied depending on required deblocking filtering strength. Also, inapplying the deblocking filter, horizontal direction filtering andvertical direction filtering may be processed in parallel.

The offset correction module may correct offset with the originalpicture in units of a pixel in the picture subjected to deblocking. Inorder to perform the offset correction on a particular picture, it ispossible to use a method of applying offset in consideration of edgeinformation of each pixel or a method of partitioning pixels of apicture into the predetermined number of regions, determining a regionto be subjected to perform offset, and applying the offset to thedetermined region.

Adaptive loop filtering (ALF) may be performed based on the valueobtained by comparing the filtered reconstructed picture and theoriginal picture. The pixels included in the picture may be divided intopredetermined groups, a filter to be applied to each of the groups maybe determined, and filtering may be individually performed for eachgroup. Information on whether to apply ALF and a luma signal may betransmitted by coding units (CU). The shape and filter coefficient of afilter for ALF may vary depending on each block. Also, the filter forALF in the same shape (fixed shape) may be applied regardless ofcharacteristics of the application target block.

The memory 155 may store the reconstructed block or picture calculatedthrough the filter module 150. The stored reconstructed block or picturemay be provided to the prediction modules 120 and 125 in performinginter prediction.

FIG. 2 is a block diagram illustrating a device for decoding a videoaccording to an embodiment of the present invention.

Referring to FIG. 2, the device 200 for decoding a video may include: anentropy decoding module 210, a rearrangement module 215, an inversequantization module 220, an inverse transform module 225, predictionmodules 230 and 235, a filter module 240, and a memory 245.

When a video bitstream is input from the device for encoding a video,the input bitstream may be decoded according to an inverse process ofthe device for encoding a video.

The entropy decoding module 210 may perform entropy decoding accordingto an inverse process of entropy encoding by the entropy encoding moduleof the device for encoding a video. For example, corresponding to themethods performed by the device for encoding a video, various methods,such as exponential Golomb coding, context-adaptive variable lengthcoding (CAVLC), and context-adaptive binary arithmetic coding (CABAC)may be applied.

The entropy decoding module 210 may decode information on intraprediction and inter prediction performed by the device for encoding avideo.

The rearrangement module 215 may perform rearrangement on the bitstreamentropy decoded by the entropy decoding module 210 based on therearrangement method used in the device for encoding a video. Therearrangement module may reconstruct and rearrange the coefficients inthe form of one-dimensional vectors to the coefficient in the form oftwo-dimensional blocks. The rearrangement module 215 may receiveinformation related to coefficient scanning performed in the device forencoding a video and may perform rearrangement via a method of inverselyscanning the coefficients based on the scanning order performed in thedevice for encoding a video.

The inverse quantization module 220 may perform inverse quantizationbased on a quantization parameter received from the device for encodinga video and the rearranged coefficients of the block.

The inverse transform module 225 may perform the inverse transform,i.e., inverse DCT, inverse DST, and inverse KLT, which is the inverseprocess of transform, i.e., DCT, DST, and KLT, performed by thetransform module on the quantization result by the device for encoding avideo. Inverse transform may be performed based on a transfer unitdetermined by the device for encoding a video. The inverse transformmodule 225 of the device for decoding a video may selectively performtransform schemes (e.g., DCT, DST, and KLT) depending on multiple piecesof information, such as the prediction method, the size of the currentblock, the prediction direction, etc.

The prediction modules 230 and 235 may generate a prediction block basedon information on prediction block generation received from the entropydecoding module 210 and previously decoded block or picture informationreceived from the memory 245.

As described above, like the operation of the device for encoding avideo, in performing intra prediction, when the size of the predictionunit is the same as the size of the transform unit, intra prediction maybe performed on the prediction unit based on the pixels positioned atthe left, the top left, and the top of the prediction unit. Inperforming intra prediction, when the size of the prediction unit isdifferent from the size of the transform unit, intra prediction may beperformed using a reference pixel based on the transform unit. Also,intra prediction using N×N partitioning may be used for only thesmallest coding unit.

The prediction modules 230 and 235 may include a prediction unitdetermination module, an inter prediction module, and an intraprediction module. The prediction unit determination module may receivea variety of information, such as prediction unit information,prediction mode information of an intra prediction method, informationon motion prediction of an inter prediction method, etc. from theentropy decoding module 210, may divide a current coding unit intoprediction units, and may determine whether inter prediction or intraprediction is performed on the prediction unit. By using informationrequired in inter prediction of the current prediction unit receivedfrom the device for encoding a video, the inter prediction module 230may perform inter prediction on the current prediction unit based oninformation of at least one of a previous picture or a subsequentpicture of the current picture including the current prediction unit.Alternatively, inter prediction may be performed based on information ofsome pre-reconstructed regions in the current picture including thecurrent prediction unit.

In order to perform inter prediction, it may be determined for thecoding unit which of a skip mode, a merge mode, an AMVP mode, and aninter block copy mode is used as the motion prediction method of theprediction unit included in the coding unit.

The intra prediction module 235 may generate a prediction block based onpixel information in the current picture. When the prediction unit is aprediction unit subjected to intra prediction, intra prediction may beperformed based on intra prediction mode information of the predictionunit received from the device for encoding a video. The intra predictionmodule 235 may include an adaptive intra smoothing (AIS) filter, areference pixel interpolation module, and a DC filter. The AIS filterperforms filtering on the reference pixel of the current block, andwhether to apply the filter may be determined depending on theprediction mode of the current prediction unit. AIS filtering may beperformed on the reference pixel of the current block by using theprediction mode of the prediction unit and AIS filter informationreceived from the device for encoding a video. When the prediction modeof the current block is a mode where AIS filtering is not performed, theAIS filter may not be applied.

When the prediction mode of the prediction unit is a prediction mode inwhich intra prediction is performed based on the pixel value obtained byinterpolating the reference pixel, the reference pixel interpolationmodule may interpolate the reference pixel to generate the referencepixel of an integer pixel or less than an integer pixel. When theprediction mode of the current prediction unit is a prediction mode inwhich a prediction block is generated without interpolation thereference pixel, the reference pixel may not be interpolated. The DCfilter may generate a prediction block through filtering when theprediction mode of the current block is a DC mode.

The reconstructed block or picture may be provided to the filter module240. The filter module 240 may include the deblocking filter, the offsetcorrection module, and the ALF.

Information on whether or not the deblocking filter is applied to thecorresponding block or picture and information on which of a strongfilter and a weak filter is applied when the deblocking filter isapplied may be received from the device for encoding a video. Thedeblocking filter of the device for decoding a video may receiveinformation on the deblocking filter from the device for encoding avideo, and may perform deblocking filtering on the corresponding block.

The offset correction module may perform offset correction on thereconstructed picture based on the type of offset correction and offsetvalue information applied to a picture in performing encoding.

The ALF may be applied to the coding unit based on information onwhether to apply the ALF, ALF coefficient information, etc. receivedfrom the device for encoding a video. The ALF information may beprovided as being included in a particular parameter set.

The memory 245 may store the reconstructed picture or block for use as areference picture or block, and may provide the reconstructed picture toan output module.

As described above, in the embodiment of the present invention, forconvenience of explanation, the coding unit is used as a termrepresenting a unit for encoding, but the coding unit may serve as aunit performing decoding as well as encoding.

In addition, a current block may represent a target block to beencoded/decoded. And, the current block may represent a coding treeblock (or a coding tree unit), a coding block (or a coding unit), atransform block (or a transform unit), a prediction block (or aprediction unit), or the like depending on an encoding/decoding step.

A picture may be encoded/decoded by divided into base blocks having asquare shape or a non-square shape. At this time, the base block may bereferred to as a coding tree unit. The coding tree unit may be definedas a coding unit of the largest size allowed within a sequence or aslice. Information regarding whether the coding tree unit has a squareshape or has a non-square shape or information regarding a size of thecoding tree unit may be signaled through a sequence parameter set, apicture parameter set, or a slice header. The coding tree unit may bedivided into smaller size partitions. At this time, if it is assumedthat a depth of a partition generated by dividing the coding tree unitis 1, a depth of a partition generated by dividing the partition havingdepth 1 may be defined as 2. That is, a partition generated by dividinga partition having a depth k in the coding tree unit may be defined ashaving a depth k+1.

A partition of arbitrary size generated by dividing a coding tree unitmay be defined as a coding unit. The coding unit may be recursivelydivided or divided into base units for performing prediction,quantization, transform, or in-loop filtering, and the like. Forexample, a partition of arbitrary size generated by dividing the codingunit may be defined as a coding unit, or may be defined as a transformunit or a prediction unit, which is a base unit for performingprediction, quantization, transform or in-loop filtering and the like.

Partitioning of a coding tree unit or a coding unit may be performedbased on at least one of a vertical line and a horizontal line. Inaddition, the number of vertical lines or horizontal lines partitioningthe coding tree unit or the coding unit may be at least one or more. Forexample, the coding tree unit or the coding unit may be divided into twopartitions using one vertical line or one horizontal line, or the codingtree unit or the coding unit may be divided into three partitions usingtwo vertical lines or two horizontal lines. Alternatively, the codingtree unit or the coding unit may be partitioned into four partitionshaving a length and a width of ½ by using one vertical line and onehorizontal line.

When a coding tree unit or a coding unit is divided into a plurality ofpartitions using at least one vertical line or at least one horizontalline, the partitions may have a uniform size or a different size.Alternatively, any one partition may have a different size from theremaining partitions.

In the embodiments described below, it is assumed that a coding treeunit or a coding unit is divided into a quad tree structure or a binarytree structure. However, it is also possible to divide a coding treeunit or a coding unit using a larger number of vertical lines or alarger number of horizontal lines.

FIG. 3 is a diagram illustrating an example of hierarchicallypartitioning a coding block based on a tree structure according to anembodiment of the present invention.

An input video signal is decoded in predetermined block units. Such adefault unit for decoding the input video signal is a coding block. Thecoding block may be a unit performing intra/inter prediction, transform,and quantization. In addition, a prediction mode (e.g., intra predictionmode or inter prediction mode) is determined in units of a coding block,and the prediction blocks included in the coding block may share thedetermined prediction mode. The coding block may be a square ornon-square block having an arbitrary size in a range of 8×8 to 64×64, ormay be a square or non-square block having a size of 128×128, 256×256,or more.

Specifically, the coding block may be hierarchically partitioned basedon at least one of a quad tree and a binary tree. Here, quad tree-basedpartitioning may mean that a 2N×2N coding block is partitioned into fourN×N coding blocks, and binary tree-based partitioning may mean that onecoding block is partitioned into two coding blocks. Even if the binarytree-based partitioning is performed, a square-shaped coding block mayexist in the lower depth.

Binary tree-based partitioning may be symmetrically or asymmetricallyperformed. The coding block partitioned based on the binary tree may bea square block or a non-square block, such as a rectangular shape. Forexample, a partition type in which the binary tree-based partitioning isallowed may comprise at least one of a symmetric type of 2N×N(horizontal directional non-square coding unit) or N×2N (verticaldirection non-square coding unit), asymmetric type of nL×2N, nR×2N,2N×nU, or 2N×nD.

Binary tree-based partitioning may be limitedly allowed to one of asymmetric or an asymmetric type partition. In this case, constructingthe coding tree unit with square blocks may correspond to quad tree CUpartitioning, and constructing the coding tree unit with symmetricnon-square blocks may correspond to binary tree partitioning.Constructing the coding tree unit with square blocks and symmetricnon-square blocks may correspond to quad and binary tree CUpartitioning.

Binary tree-based partitioning may be performed on a coding block wherequad tree-based partitioning is no longer performed. Quad tree-basedpartitioning may no longer be performed on the coding block partitionedbased on the binary tree.

Furthermore, partitioning of a lower depth may be determined dependingon a partition type of an upper depth. For example, if binary tree-basedpartitioning is allowed in two or more depths, only the same type as thebinary tree partitioning of the upper depth may be allowed in the lowerdepth. For example, if the binary tree-based partitioning in the upperdepth is performed with 2N×N type, the binary tree-based partitioning inthe lower depth is also performed with 2N×N type. Alternatively, if thebinary tree-based partitioning in the upper depth is performed with N×2Ntype, the binary tree-based partitioning in the lower depth is alsoperformed with N×2N type.

On the contrary, it is also possible to allow, in a lower depth, only atype different from a binary tree partitioning type of an upper depth.

It may be possible to limit only a specific type of binary tree basedpartitioning to be used for sequence, slice, coding tree unit, or codingunit. As an example, only 2N×N type or N×2N type of binary tree-basedpartitioning may be allowed for the coding tree unit. An availablepartition type may be predefined in an encoder or a decoder. Orinformation on available partition type or on unavailable partition typeon may be encoded and then signaled through a bitstream.

FIGS. 5A and 5B are diagrams illustrating an example in which only aspecific type of binary tree-based partitioning is allowed. FIG. 5Ashows an example in which only N×2N type of binary tree-basedpartitioning is allowed, and FIG. 5B shows an example in which only 2N×Ntype of binary tree-based partitioning is allowed. In order to implementadaptive partitioning based on the quad tree or binary tree, informationindicating quad tree-based partitioning, information on the size/depthof the coding block that quad tree-based partitioning is allowed,information indicating binary tree-based partitioning, information onthe size/depth of the coding block that binary tree-based partitioningis allowed, information on the size/depth of the coding block thatbinary tree-based partitioning is not allowed, information on whetherbinary tree-based partitioning is performed in a vertical direction or ahorizontal direction, etc. may be used.

In addition, information on the number of times a binary treepartitioning is allowed, a depth at which the binary tree partitioningis allowed, or the number of the depths at which the binary treepartitioning is allowed may be obtained for a coding tree unit or aspecific coding unit. The information may be encoded in units of acoding tree unit or a coding unit, and may be transmitted to a decoderthrough a bitstream.

For example, a syntax ‘max_binary_depth_idx_minus1’ indicating a maximumdepth at which binary tree partitioning is allowed may beencoded/decoded through a bitstream. In this case,max_binary_depth_idx_minus1+1 may indicate the maximum depth at whichthe binary tree partitioning is allowed.

Referring to the example shown in FIG. 6, in FIG. 6, the binary treepartitioning has been performed for a coding unit having a depth of 2and a coding unit having a depth of 3. Accordingly, at least one ofinformation indicating the number of times the binary tree partitioningin the coding tree unit has been performed (i.e., 2 times), informationindicating the maximum depth which the binary tree partitioning has beenallowed in the coding tree unit (i.e., depth 3), or the number of depthsin which the binary tree partitioning has been performed in the codingtree unit (i.e., 2 (depth 2 and depth 3)) may be encoded/decoded througha bitstream.

As another example, at least one of information on the number of timesthe binary tree partitioning is permitted, the depth at which the binarytree partitioning is allowed, or the number of the depths at which thebinary tree partitioning is allowed may be obtained for each sequence oreach slice. For example, the information may be encoded in units of asequence, a picture, or a slice unit and transmitted through abitstream. Accordingly, at least one of the number of the binary treepartitioning in a first slice, the maximum depth in which the binarytree partitioning is allowed in the first slice, or the number of depthsin which the binary tree partitioning is performed in the first slicemay be difference from a second slice. For example, in the first slice,binary tree partitioning may be permitted for only one depth, while inthe second slice, binary tree partitioning may be permitted for twodepths.

As another example, the number of times the binary tree partitioning ispermitted, the depth at which the binary tree partitioning is allowed,or the number of depths at which the binary tree partitioning is allowedmay be set differently according to a time level identifier (TemporalID)of a slice or a picture. Here, the temporal level identifier(TemporalID) is used to identify each of a plurality of layers of videohaving a scalability of at least one of view, spatial, temporal orquality.

As shown in FIG. 3, the first coding block 300 with the partition depth(split depth) of k may be partitioned into multiple second coding blocksbased on the quad tree. For example, the second coding blocks 310 to 340may be square blocks having the half width and the half height of thefirst coding block, and the partition depth of the second coding blockmay be increased to k+1.

The second coding block 310 with the partition depth of k+1 may bepartitioned into multiple third coding blocks with the partition depthof k+2. Partitioning of the second coding block 310 may be performed byselectively using one of the quad tree and the binary tree depending ona partitioning method. Here, the partitioning method may be determinedbased on at least one of the information indicating quad tree-basedpartitioning and the information indicating binary tree-basedpartitioning.

When the second coding block 310 is partitioned based on the quad tree,the second coding block 310 may be partitioned into four third codingblocks 310 a having the half width and the half height of the secondcoding block, and the partition depth of the third coding block 310 amay be increased to k+2. In contrast, when the second coding block 310is partitioned based on the binary tree, the second coding block 310 maybe partitioned into two third coding blocks. Here, each of two thirdcoding blocks may be a non-square block having one of the half width andthe half height of the second coding block, and the partition depth maybe increased to k+2. The second coding block may be determined as anon-square block of a horizontal direction or a vertical directiondepending on a partitioning direction, and the partitioning directionmay be determined based on the information on whether binary tree-basedpartitioning is performed in a vertical direction or a horizontaldirection.

In the meantime, the second coding block 310 may be determined as a leafcoding block that is no longer partitioned based on the quad tree or thebinary tree. In this case, the leaf coding block may be used as aprediction block or a transform block.

Like partitioning of the second coding block 310, the third coding block310 a may be determined as a leaf coding block, or may be furtherpartitioned based on the quad tree or the binary tree.

In the meantime, the third coding block 310 b partitioned based on thebinary tree may be further partitioned into coding blocks 310 b-2 of avertical direction or coding blocks 310 b-3 of a horizontal directionbased on the binary tree, and the partition depth of the relevant codingblocks may be increased to k+3. Alternatively, the third coding block310 b may be determined as a leaf coding block 310 b-1 that is no longerpartitioned based on the binary tree. In this case, the coding block 310b-1 may be used as a prediction block or a transform block. However, theabove partitioning process may be limitedly performed based on at leastone of the information on the size/depth of the coding block that quadtree-based partitioning is allowed, the information on the size/depth ofthe coding block that binary tree-based partitioning is allowed, and theinformation on the size/depth of the coding block that binary tree-basedpartitioning is not allowed.

A number of a candidate that represent a size of a coding block may belimited to a predetermined number, or a size of a coding block in apredetermined unit may have a fixed value. As an example, the size ofthe coding block in a sequence or in a picture may be limited to have256×256, 128×128, or 32×32. Information indicating the size of thecoding block in the sequence or in the picture may be signaled through asequence header or a picture header.

As a result of partitioning based on a quad tree and a binary tree, acoding unit may be represented as square or rectangular shape of anarbitrary size.

A coding block is encoded using at least one of a skip mode, intraprediction, inter prediction, or a skip method. Once a coding block isdetermined, a prediction block may be determined through predictivepartitioning of the coding block. The predictive partitioning of thecoding block may be performed by a partition mode (Part mode) indicatinga partition type of the coding block. A size or a shape of theprediction block may be determined according to the partition mode ofthe coding block. For example, a size of a prediction block determinedaccording to the partition mode may be equal to or smaller than a sizeof a coding block.

FIG. 7 is a diagram illustrating a partition mode that may be applied toa coding block when the coding block is encoded by inter prediction.

When a coding block is encoded by inter prediction, one of 8partitioning modes may be applied to the coding block, as in the exampleshown in FIG. 7.

When a coding block is encoded by intra prediction, a partition modePART_2N×2N or a partition mode PART_N×N may be applied to the codingblock.

PART_N×N may be applied when a coding block has a minimum size. Here,the minimum size of the coding block may be pre-defined in an encoderand a decoder. Or, information regarding the minimum size of the codingblock may be signaled via a bitstream. For example, the minimum size ofthe coding block may be signaled through a slice header, so that theminimum size of the coding block may be defined per slice.

In general, a prediction block may have a size from 64×64 to 4×4.However, when a coding block is encoded by inter prediction, it may berestricted that the prediction block does not have a 4×4 size in orderto reduce memory bandwidth when performing motion compensation.

FIG. 8 is a diagram illustrating types of pre-defined intra predictionmodes for a device for encoding/decoding a video according to anembodiment of the present invention.

The device for encoding/decoding a video may perform intra predictionusing one of pre-defined intra prediction modes. The pre-defined intraprediction modes for intra prediction may include non-directionalprediction modes (e.g., a planar mode, a DC mode) and 33 directionalprediction modes.

Alternatively, in order to enhance accuracy of intra prediction, alarger number of directional prediction modes than the 33 directionalprediction modes may be used. That is, M extended directional predictionmodes may be defined by subdividing angles of the directional predictionmodes (M>33), and a directional prediction mode having a predeterminedangle may be derived using at least one of the 33 pre-defineddirectional prediction modes.

A larger number of intra prediction modes than 35 intra prediction modesshown in FIG. 8 may be used. For example, a larger number of intraprediction modes than the 35 intra prediction modes can be used bysubdividing angles of directional prediction modes or by deriving adirectional prediction mode having a predetermined angle using at leastone of a pre-defined number of directional prediction modes. At thistime, the use of a larger number of intra prediction modes than the 35intra prediction modes may be referred to as an extended intraprediction mode.

FIG. 9 shows an example of extended intra prediction modes, and theextended intra prediction modes may include two non-directionalprediction modes and 65 extended directional prediction modes. The samenumbers of the extended intra prediction modes may be used for a lumacomponent and a chroma component, or a different number of intraprediction modes may be used for each component. For example, 67extended intra prediction modes may be used for the luma component, and35 intra prediction modes may be used for the chroma component.

Alternatively, depending on the chroma format, a different number ofintra prediction modes may be used in performing intra prediction. Forexample, in the case of the 4:2:0 format, 67 intra prediction modes maybe used for the luma component to perform intra prediction and 35 intraprediction modes may be used for the chroma component. In the case ofthe 4:4:4 format, 67 intra prediction modes may be used for both theluma component and the chroma component to perform intra prediction.

Alternatively, depending on the size and/or shape of the block, adifferent number of intra prediction modes may be used to perform intraprediction. That is, depending on the size and/or shape of the PU or CU,35 intra prediction modes or 67 intra prediction modes may be used toperform intra prediction. For example, when the CU or PU has the sizeless than 64×64 or is asymmetrically partitioned, 35 intra predictionmodes may be used to perform intra prediction. When the size of the CUor PU is equal to or greater than 64×64, 67 intra prediction modes maybe used to perform intra prediction. 65 directional intra predictionmodes may be allowed for Intra_2N×2N, and only 35 directional intraprediction modes may be allowed for Intra_N×N.

A size of a block to which the extended intra prediction mode is appliedmay be set differently for each sequence, picture or slice. For example,it is set that the extended intra prediction mode is applied to a block(e.g., CU or PU) which has a size greater than 64×64 in the first slice.On the other hands, it is set that the extended intra prediction mode isapplied to a block which has a size greater than 32×32 in the secondslice. Information representing a size of a block to which the extendedintra prediction mode is applied may be signaled through in units of asequence, a picture, or a slice. For example, the information indicatingthe size of the block to which the extended intra prediction mode isapplied may be defined as ‘log 2_extended_intra_mode_size_minus4’obtained by taking a logarithm of the block size and then subtractingthe integer 4. For example, if a value of log2_extended_intra_mode_size_minus4 is 0, it may indicate that theextended intra prediction mode may be applied to a block having a sizeequal to or greater than 16×16. And if a value of log2_extended_intra_mode_size_minus4 is 1, it may indicate that theextended intra prediction mode may be applied to a block having a sizeequal to or greater than 32×32.

As described above, the number of intra prediction modes may bedetermined in consideration of at least one of a color component, achroma format, and a size or a shape of a block. In addition, the numberof intra prediction mode candidates (e.g., the number of MPMs) used fordetermining an intra prediction mode of a current block to beencoded/decoded may also be determined according to at least one of acolor component, a color format, and the size or a shape of a block. Amethod of determining an intra prediction mode of a current block to beencoded/decoded and a method of performing intra prediction using thedetermined intra prediction mode will be described with the drawings.

FIG. 10 is a flowchart briefly illustrating an intra prediction methodaccording to an embodiment of the present invention.

Referring to FIG. 10, an intra prediction mode of the current block maybe determined at step S1000.

Specifically, the intra prediction mode of the current block may bederived based on a candidate list and an index. Here, the candidate listcontains multiple candidates, and the multiple candidates may bedetermined based on an intra prediction mode of the neighboring blockadjacent to the current block. The neighboring block may include atleast one of blocks positioned at the top, the bottom, the left, theright, and the corner of the current block. The index may specify one ofthe multiple candidates of the candidate list. The candidate specifiedby the index may be set to the intra prediction mode of the currentblock.

An intra prediction mode used for intra prediction in the neighboringblock may be set as a candidate. Also, an intra prediction mode havingdirectionality similar to that of the intra prediction mode of theneighboring block may be set as a candidate. Here, the intra predictionmode having similar directionality may be determined by adding orsubtracting a predetermined constant value to or from the intraprediction mode of the neighboring block. The predetermined constantvalue may be an integer, such as one, two, or more.

The candidate list may further include a default mode. The default modemay include at least one of a planar mode, a DC mode, a vertical mode,and a horizontal mode. The default mode may be adaptively addedconsidering the maximum number of candidates that can be included in thecandidate list of the current block.

The maximum number of candidates that can be included in the candidatelist may be three, four, five, six, or more. The maximum number ofcandidates that can be included in the candidate list may be a fixedvalue preset in the device for encoding/decoding a video, or may bevariably determined based on a characteristic of the current block. Thecharacteristic may mean the location/size/shape of the block, thenumber/type of intra prediction modes that the block can use, a colortype, a color format, etc. Alternatively, information indicating themaximum number of candidates that can be included in the candidate listmay be signaled separately, and the maximum number of candidates thatcan be included in the candidate list may be variably determined usingthe information. The information indicating the maximum number ofcandidates may be signaled in at least one of a sequence level, apicture level, a slice level, and a block level.

When the extended intra prediction modes and the 35 pre-defined intraprediction modes are selectively used, the intra prediction modes of theneighboring blocks may be transformed into indexes corresponding to theextended intra prediction modes, or into indexes corresponding to the 35intra prediction modes, whereby candidates can be derived. For transformto an index, a pre-defined table may be used, or a scaling operationbased on a predetermined value may be used. Here, the pre-defined tablemay define a mapping relation between different intra prediction modegroups (e.g., extended intra prediction modes and 35 intra predictionmodes).

For example, when the left neighboring block uses the 35 intraprediction modes and the intra prediction mode of the left neighboringblock is 10 (a horizontal mode), it may be transformed into an index of16 corresponding to a horizontal mode in the extended intra predictionmodes.

Alternatively, when the top neighboring block uses the extended intraprediction modes and the intra prediction mode the top neighboring blockhas an index of 50 (a vertical mode), it may be transformed into anindex of 26 corresponding to a vertical mode in the 35 intra predictionmodes.

Based on the above-described method of determining the intra predictionmode, the intra prediction mode may be derived independently for each ofthe luma component and the chroma component, or the intra predictionmode of the chroma component may be derived depending on the intraprediction mode of the luma component.

Specifically, the intra prediction mode of the chroma component may bedetermined based on the intra prediction mode of the luma component asshown in the following Table 1.

TABLE 1 IntraPredModeY[xCb][yCb] Intra_chroma_pred_mode[xCb][yCb] 0 2610 1 X(0 <= X <= 34) 0 34 0 0 0 0 1 26 34 26 26 26 2 10 10 34 10 10 3 11 1 34 1 4 0 26 10 1 X

In Table 1, intra_chroma_pred_mode_means information signaled to specifythe intra prediction mode of the chroma component, and IntraPredModeYindicates the intra prediction mode of the luma component.

Referring to FIG. 10, a reference sample for intra prediction of thecurrent block may be derived at step S1010.

Specifically, a reference sample for intra prediction may be derivedbased on a neighboring sample of the current block. The neighboringsample may be a reconstructed sample of the neighboring block, and thereconstructed sample may be a reconstructed sample before an in-loopfilter is applied or a reconstructed sample after the in-loop filter isapplied.

A neighboring sample reconstructed before the current block may be usedas the reference sample, and a neighboring sample filtered based on apredetermined intra filter may be used as the reference sample.Filtering of neighboring samples using an intra filter may also bereferred to as reference sample smoothing. The intra filter may includeat least one of the first intra filter applied to multiple neighboringsamples positioned on the same horizontal line and the second intrafilter applied to multiple neighboring samples positioned on the samevertical line. Depending on the positions of the neighboring samples,one of the first intra filter and the second intra filter may beselectively applied, or both intra filters may be applied. At this time,at least one filter coefficient of the first intra filter or the secondintra filter may be (1, 2, 1), but is not limited thereto.

Filtering may be adaptively performed based on at least one of the intraprediction mode of the current block and the size of the transform blockfor the current block. For example, when the intra prediction mode ofthe current block is the DC mode, the vertical mode, or the horizontalmode, filtering may not be performed. When the size of the transformblock is N×M, filtering may not be performed. Here, N and M may be thesame values or different values, or may be values of 4, 8, 16, or more.For example, if the size of the transform block is 4×4, filtering maynot be performed. Alternatively, filtering may be selectively performedbased on the result of a comparison of a pre-defined threshold and thedifference between the intra prediction mode of the current block andthe vertical mode (or the horizontal mode). For example, when thedifference between the intra prediction mode of the current block andthe vertical mode is greater than a threshold, filtering may beperformed. The threshold may be defined for each size of the transformblock as shown in Table 2.

TABLE 2 8 × 8 transform 16 × 16 transform 32 × 32 transform Threshold 71 0

The intra filter may be determined as one of multiple intra filtercandidates pre-defined in the device for encoding/decoding a video. Tothis end, an index specifying an intra filter of the current block amongthe multiple intra filter candidates may be signaled. Alternatively, theintra filter may be determined based on at least one of the size/shapeof the current block, the size/shape of the transform block, informationon the filter strength, and variations of the neighboring samples.

Referring to FIG. 10, intra prediction may be performed using the intraprediction mode of the current block and the reference sample at stepS1020.

That is, the prediction sample of the current block may be obtainedusing the intra prediction mode determined at step S1000 and thereference sample derived at step S1010. However, in the case of intraprediction, a boundary sample of the neighboring block may be used, andthus quality of the prediction picture may be decreased. Therefore, acorrection process may be performed on the prediction sample generatedthrough the above-described prediction process, and will be described indetail with reference to FIGS. 11 to 13. However, the correction processis not limited to being applied only to the intra prediction sample, andmay be applied to an inter prediction sample or the reconstructedsample.

FIG. 11 is a diagram illustrating a method of correcting a predictionsample of a current block based on differential information ofneighboring samples according to an embodiment of the present invention.

The prediction sample of the current block may be corrected based on thedifferential information of multiple neighboring samples for the currentblock. The correction may be performed on all prediction samples in thecurrent block, or may be performed on prediction samples inpredetermined partial regions. The partial regions may be one row/columnor multiple rows/columns, and these may be preset regions for correctionin the device for encoding/decoding a video. For example, correction maybe performed on a one row/column located at a boundary of the currentblock or may be performed on plurality of rows/columns from a boundaryof the current block. Alternatively, the partial regions may be variablydetermined based on at least one of the size/shape of the current blockand the intra prediction mode.

The neighboring samples may belong to the neighboring blocks positionedat the top, the left, and the top left corner of the current block. Thenumber of neighboring samples used for correction may be two, three,four, or more. The positions of the neighboring samples may be variablydetermined depending on the position of the prediction sample which isthe correction target in the current block. Alternatively, some of theneighboring samples may have fixed positions regardless of the positionof the prediction sample which is the correction target, and theremaining neighboring samples may have variable positions depending onthe position of the prediction sample which is the correction target.

The differential information of the neighboring samples may mean adifferential sample between the neighboring samples, or may mean a valueobtained by scaling the differential sample by a predetermined constantvalue (e.g., one, two, three, etc.). Here, the predetermined constantvalue may be determined considering the position of the predictionsample which is the correction target, the position of the column or rowincluding the prediction sample which is the correction target, theposition of the prediction sample within the column or row, etc.

For example, when the intra prediction mode of the current block is thevertical mode, differential samples between the top left neighboringsample p(−1, −1) and neighboring samples p (−1, y) adjacent to the leftboundary of the current block may be used to obtain the final predictionsample as shown in Equation 1.

P′(0,y)=P(0,y)+((p(−1,y)−p(−1,−1))>>1 for y=0 . . . N−1  [Equation 1]

For example, when the intra prediction mode of the current block is thehorizontal mode, differential samples between the top left neighboringsample p(−1, −1) and neighboring samples p(x, −1) adjacent to the topboundary of the current block may be used to obtain the final predictionsample as shown in Equation 2.

P′(x,0)=p(x,0)+((p(x,−1 )−p(−1,−1))>>1 for x=0 . . . N−1  [Equation 2]

For example, when the intra prediction mode of the current block is thevertical mode, differential samples between the top left neighboringsample p(−1, −1) and neighboring samples p(−1, y) adjacent to the leftboundary of the current block may be used to obtain the final predictionsample. Here, the differential sample may be added to the predictionsample, or the differential sample may be scaled by a predeterminedconstant value, and then added to the prediction sample. Thepredetermined constant value used in scaling may be determineddifferently depending on the column and/or row. For example, theprediction sample may be corrected as shown in Equation 3 and Equation4.

P′(0,y)=P(0,y)+((p(−1,y)−p(−1,−1))>>1 for y=0 . . . N−1  [Equation 3]

P′(1,y)=P(1,y)+((p(−1,y)−p(−1,−1))>>2 for y=0 . . . N−1  [Equation 4]

For example, when the intra prediction mode of the current block is thehorizontal mode, differential samples between the top left neighboringsample p(−1, −1) and neighboring samples p(x, −1) adjacent to the topboundary of the current block may be used to obtain the final predictionsample, as described in the case of the vertical mode. For example, theprediction sample may be corrected as shown in Equation 5 and Equation6.

P′(x,0)=p(x,0)+((p(x,−1)−p(−1,−1))>>1 for x=0 . . . N−1  [Equation 5]

P′(x,1)=p(x,1)+((p(x,−1)−p(−1,−1))>>2 for x=0 . . . N−1  [Equation 6]

FIGS. 12 and 13 are diagrams illustrating a method of correcting aprediction sample based on a predetermined correction filter accordingto an embodiment of the present invention.

The prediction sample may be corrected based on the neighboring sampleof the prediction sample which is the correction target and apredetermined correction filter. Here, the neighboring sample may bespecified by an angular line of the directional prediction mode of thecurrent block, or may be at least one sample positioned on the sameangular line as the prediction sample which is the correction target.Also, the neighboring sample may be a prediction sample in the currentblock, or may be a reconstructed sample in a neighboring blockreconstructed before the current block.

At least one of the number of taps, strength, and a filter coefficientof the correction filter may be determined based on at least one of theposition of the prediction sample which is the correction target,whether or not the prediction sample which is the correction target ispositioned on the boundary of the current block, the intra predictionmode of the current block, angle of the directional prediction mode, theprediction mode (inter or intra mode) of the neighboring block, and thesize/shape of the current block.

Referring to FIG. 12, when the directional prediction mode has an indexof 2 or 34, at least one prediction/reconstructed sample positioned atthe bottom left of the prediction sample which is the correction targetand the predetermined correction filter may be used to obtain the finalprediction sample. Here, the prediction/reconstructed sample at thebottom left may belong to a previous line of a line including theprediction sample which is the correction target. Theprediction/reconstructed sample at the bottom left may belong to thesame block as the current sample, or to neighboring block adjacent tothe current block.

Filtering for the prediction sample may be performed only on the linepositioned at the block boundary, or may be performed on multiple lines.The correction filter where at least one of the number of filter tapsand a filter coefficient is different for each of lines may be used. Forexample, a (½, ½) filter may be used for the left first line closest tothe block boundary, a ( 12/16, 4/16) filter may be used for the secondline, a ( 14/16, 2/16) filter may be used for the third line, and a (15/16, 1/16) filter may be used for the fourth line.

Alternatively, when the directional prediction mode has an index of 3 to6 or 30 to 33, filtering may be performed on the block boundary as shownin FIG. 13, and a 3-tap correction filter may be used to correct theprediction sample. Filtering may be performed using the bottom leftsample of the prediction sample which is the correction target, thebottom sample of the bottom left sample, and a 3-tap correction filterthat takes as input the prediction sample which is the correctiontarget. The position of neighboring sample used by the correction filtermay be determined differently based on the directional prediction mode.The filter coefficient of the correction filter may be determineddifferently depending on the directional prediction mode.

Different correction filters may be applied depending on whether theneighboring block is encoded in the inter mode or the intra mode. Whenthe neighboring block is encoded in the intra mode, a filtering methodwhere more weight is given to the prediction sample may be used,compared to when the neighboring block is encoded in the inter mode. Forexample, in the case of that the intra prediction mode is 34, when theneighboring block is encoded in the inter mode, a (½, ½) filter may beused, and when the neighboring block is encoded in the intra mode, a (4/16, 12/16) filter may be used.

The number of lines to be filtered in the current block may varydepending on the size/shape of the current block (e.g., the coding blockor the prediction block). For example, when the size of the currentblock is equal to or less than 32×32, filtering may be performed on onlyone line at the block boundary; otherwise, filtering may be performed onmultiple lines including the one line at the block boundary.

FIGS. 12 and 13 are based on the case where the 35 intra predictionmodes in FIG. 7 are used, but may be equally/similarly applied to thecase where the extended intra prediction modes are used.

FIG. 14 shows a range of reference samples for intra predictionaccording to an embodiment to which the present invention is applied.

Intra prediction of a current block may be performed using a referencesample derived based on a reconstructed sample included in a neighboringblock. Here, the reconstructed sample means that encoding/decoding iscompleted before encoding/decoding the current block. For example, intraprediction for the current block may be performed based on at least oneof reference samples P(−1, −1), P(−1, y) (0<=y<=2N−1) and P(x, −1)(0<=x<=2N−1). At this time, filtering on reference samples isselectively performed based on at least one of an intra prediction mode(e.g., index, directionality, angle, etc. of the intra prediction mode)of the current block or a size of a transform block related to thecurrent block.

Filtering on reference samples may be performed using an intra filterpre-defined in an encoder and a decoder. For example, an intra filterwith a filter coefficient of (1,2,1) or an intra filter with a filtercoefficient of (2,3,6,3,2) may be used to derive final reference samplesfor use in intra prediction.

Alternatively, at least one of a plurality of intra filter candidatesmay be selected to perform filtering on reference samples. Here, theplurality of intra filter candidates may differ from each other in atleast one of a filter strength, a filter coefficient or a tap number(e.g., a number of filter coefficients, a filter length). A plurality ofintra filter candidates may be defined in at least one of a sequence, apicture, a slice, or a block level. That is, a sequence, a picture, aslice, or a block in which the current block is included may use thesame plurality of intra filter candidates.

Hereinafter, for convenience of explanation, it is assumed that aplurality of intra filter candidates includes a first intra filter and asecond intra filter. It is also assumed that the first intra filter is a(1,2,1) 3-tap filter and the second intra filter is a (2,3,6,3,2) 5-tapfilter.

When reference samples are filtered by applying a first intra filter,the filtered reference samples may be derived as shown in Equation 7.

P(−1,−1)=(P(−1,0)+2P(−1,−1)+P(0,−1)+2)>>2

P(−1,y)=(P(−1,y+1 )+2P(−1,y)+P(−1,y−1)+2)>>2

P(x,−1)=(P(x+1,−1)+2P(x,−1)+P(x−1,−1)+2)>>2  [Equation 7]

When reference samples are filtered by applying the second intra filter,the filtered reference samples may be derived as shown in the followingequation 8.

P(−1,−1)=(2P(−2,0)+3P(−1,0)+6P(−1,−1)+3P(0,−1)+2P(0,−2)+8)>>4

P(−1,y)=(2P(−1,y+2)+3P(−1,y+1)+6P(−1,y)+3P(−1,y−1)+2P(−1,y−2)+8)>>4

P(x,−1)=(2P(x+2,−1)+3P(x+1,−1)+6P(x,−1)+3P(x−1,−1)+2P(x−2,−1)+8)>>4  [Equation8]

In the above Equations 7 and 8, x may be an integer between 0 and 2N−2,and y may be an integer between 0 and 2N−2.

Alternatively, based on a position of a reference sample, one of aplurality of intra filter candidates may be determined, and filtering onthe reference sample may be performed by using the determined one. Forexample, a first intra filter may be applied to reference samplesincluded in a first range, and a second intra filter may be applied toreference samples included in a second range. Here, the first range andthe second range may be distinguished based on whether they are adjacentto a boundary of a current block, whether they are located at a top sideor a left side of a current block, or whether they are adjacent to acorner of a current block. For example, as shown in FIG. 15, filteringon reference samples (P (−1, −1), P (−1,0), P (−1,1), . . . , P (−1,N−1) and P (0, −1), P (1, −1), . . . ) which are adjacent to a boundaryof the current block is performed by applying a first intra filter asshown in Equation 7, and filtering on the other reference samples whichare not adjacent to a boundary of the current block is performed byapplying a second reference filter as shown in Equation 8. It ispossible to select one of a plurality of intra filter candidates basedon a transform type used for a current block, and perform filtering onreference samples using the selected one. Here, the transform type maymean (1) a transform scheme such as DCT, DST or KLT, (2) a transformmode indicator such as a 2D transform, 1D transform or non-transform or(3) the number of transforms such as a first transform and a secondtransform. Hereinafter, for convenience of description, it is assumedthat the transform type means the transform scheme such as DCT, DST andKLT.

For example, if a current block is encoded using a DCT, filtering may beperformed using a first intra filter, and if a current block is encodedusing a DST, filtering may be performed using a second intra filter. Or,if a current block is encoded using DCT or DST, filtering may beperformed using a first intra filter, and if the current block isencoded using a KLT, filtering may be performed using a second intrafilter.

Filtering may be performed using a filter selected based on a transformtype of a current block and a position of a reference sample. Forexample, if a current block is encoded using the a DCT, filtering onreference samples P (−1, −1), P (−1,0), P (−1,1), . . . , P (−1, N−1)and P (0, −1), P (1, −1), . . . , P (N−1, -1) may be performed by usinga first intra filter, and filtering on other reference samples may beperformed by using a second intra filter. If a current block is encodedusing a DST, filtering on reference samples P (−1, −1), P (−1,0), P(−1,1), . . . , P (−1, N−1) and P (0, −1), P (1, −1), . . . , P (N−1,−1) may be performed by using a second intra filter, and filtering onother reference samples may be performed by using a first intra filter.

One of a plurality of intra filter candidates may be selected based onwhether a transform type of a neighboring block including a referencesample is the same as a transform type of a current block, and thefiltering may be performed using the selected intra filter candidate.For example, when a current block and a neighboring block use the sametransform type, filtering is performed using a first intra filter, andwhen transform types of a current block and of a neighboring block aredifferent from each other, the second intra filter may be used toperform filtering.

It is possible to select any one of a plurality of intra filtercandidates based on a transform type of a neighboring block and performfiltering on a reference sample using the selected one. That is, aspecific filter may be selected in consideration of a transform type ofa block in which a reference sample is included. For example, as shownin FIG. 16, if a block adjacent to left/lower left of a current block isa block encoded using a DCT, and a block adjacent to top/top right of acurrent block is a block encoded using a DST, filtering on referencesamples adjacent to left/lower left of a current block is performed byapplying a first intra filter and filtering on reference samplesadjacent to top/top right of a current block is performed by applying asecond intra filter.

In units of a predetermined region, a filter usable in the correspondingregion may be defined. Herein, the unit of the predetermined region maybe any one of a sequence, a picture, a slice, a block group (e.g., a rowof coding tree units) or a block (e.g., a coding tree unit) Or, anotherregion may be defined that shares one or more filters. A referencesample may be filtered by using a filter mapped to a region in which acurrent block is included.

For example, as shown in FIG. 17, it is possible to perform filtering onreference samples using different filters in CTU units. In this case,information indicating whether the same filter is used in a sequence ora picture, a type of filter used for each CTU, an index specifying afilter used in the corresponding CTU among an available intra filtercandidates may be signaled via a sequence parameter set (SPS) or apicture parameter set (PPS).

The above-described intra filter may be applied in units of a codingunit. For example, filtering may be performed by applying a first intrafilter or a second intra filter to reference samples around a codingunit.

When a directional prediction mode or DC mode is used, deterioration ofimage quality may occur at a block boundary. On the other hand, inplanar mode, there is an advantage that the deterioration of imagequality at the block boundary is relatively small as compared with theabove prediction modes.

Planar prediction may be performed by generating first prediction image(i.e., a first prediction sample) in a horizontal direction and secondprediction image (i.e., a second prediction sample) in a verticaldirection using reference samples and then performing a weightedprediction of the first prediction image and the second predictionimage.

Here, the first prediction image may be generated based on referencesamples which are adjacent to the current block and positioned in thehorizontal direction of a prediction sample. For example, the firstprediction image may be generated based on a weighted sum of referencesamples positioned in the horizontal direction of the prediction sample,and a weight applied to each of the reference samples may be determinedbased on a distance from a prediction target sample or a size of thecurrent block. The samples positioned in the horizontal direction mayinclude a left reference sample located on a left side of the predictiontarget sample and a right reference sample located on a right side ofthe prediction target sample. At this time, the right reference samplemay be derived from a top reference sample of the current block. Forexample, the right reference sample may be derived by copying a value ofone of top reference samples, or may be derived by a weighted sum or anaverage value of top reference samples. Here, the top reference samplemay be a reference sample located on the same vertical line as the rightreference sample, and may be a reference sample adjacent to a top rightcorner of the current block. Alternatively, the position of the topreference sample may be determined differently depending on a positionof the prediction target sample.

The second prediction image may be generated based on reference sampleswhich are adjacent to the current block and positioned in a verticaldirection of a prediction sample. For example, the second predictionimage may be generated based on a weighted sum of reference samplespositioned in the vertical direction of the prediction sample, and aweight applied to each of the reference samples may be determined basedon a distance from a prediction target sample or a size of the currentblock. The samples located in the vertical direction may include a topreference sample located on a top side of the prediction target sampleand a bottom reference sample located on a bottom side of the predictiontarget sample. At this time, the bottom reference sample may be derivedfrom a left reference sample of the current block. For example, thebottom reference sample may be derived by copying a value of one of leftreference samples, or may be derived by a weighted sum or an averagevalue of left reference samples. Here, the left reference sample may bea reference sample located on the same horizontal line as the bottomreference sample, and may be a reference sample adjacent to a bottomleft corner of the current block. Alternatively, the position of the topreference sample may be determined differently depending on a positionof the prediction target sample.

As another example, it is also possible to derive the right referencesample and the bottom reference sample using a plurality of referencesamples.

For example, the right reference sample or the bottom reference samplemay be derived using both the top reference sample and the leftreference sample of the current block. For example, at least one of theright reference sample or the bottom reference sample may be determinedas a weighted sum or an average of the top reference sample and the leftreference sample of the current block.

Alternatively, the weighted sum or the average of the top referencesample and the left reference sample of the current block may becalculated, and then the right reference sample may be derived from theweighted sum or the average value of the calculated value and the topreference sample. If the right reference sample is derived throughcalculation of the weighted sum of the calculated value and the topreference sample, the weight may be determined in a consideration of asize of the current block, a shape of the current block, a position ofthe right reference sample, or a distance between the right referencesample and the top reference sample.

In addition, after calculating the weighted sum or the average of thetop reference sample and the left reference sample of the current block,the bottom reference sample may be derived from the weighted sum or theaverage value of the calculated value and the left reference sample. Ifthe right reference sample is derived through the weighted sum of thecalculated value and the left reference sample, the weight may bedetermined in a consideration of a size of the current block, a shape ofthe current block, a position of the bottom reference sample, or adistance between the bottom reference sample and the left referencesample.

Positions of multiple reference samples used to derive the rightreference sample or the left reference sample may be fixed or may varydepending on a position of a prediction target sample. For example, thetop reference sample may have a fixed position such as a referencesample adjacent to the top right corner of the current block and locatedon the same vertical line as the right reference sample, and the leftreference sample may have a fixed position such as a reference sampleadjacent to a bottom left corner of the current block and located on thesame horizontal line as the bottom reference sample. Alternatively, whenderiving the right reference sample, the top reference sample which hasa fixed location such as a reference sample adjacent to the top rightcorner of the current block is used, while the left reference samplesuch as a reference sample located on the same horizontal line as theprediction target sample is used. When deriving the bottom referencesample, the left reference sample which has a fixed location such as areference sample adjacent to the bottom left corner of the current blockis used, while the top reference sample such as a reference samplelocated on the same vertical line as the prediction target sample isused.

FIGS. 18A and 18B are diagrams showing an example of deriving a rightreference sample or a bottom reference sample using a plurality ofreference samples. It will be assumed that a current block is a blockhaving a size of W×H.

Referring to FIG. 18A, first, a bottom right reference sample P(W, H)may be generated based on a weighted sum or an average value of a topreference sample P(W, −1) and a left reference sample P(−1, H) of thecurrent block. And, a right reference sample P(W, y) for a predictiontarget sample (x, y) may be generated based on the bottom rightreference sample P(W, H) and the top reference sample P(W, −1). Forexample, the right prediction sample P (W, y) may be calculated as aweighted sum or an average value of the bottom right reference sampleP(W, H) and the top reference sample P(W, −1). In addition, a bottomreference sample P(x, H) for the prediction target sample (x, y) may begenerated based on the bottom right reference sample P(W, H) and a leftreference sample P(−1, H). For example, the bottom reference sample P(x,H) may be calculated as a weighted sum or an average value of the bottomright reference sample P(W, H) and the left reference sample P(−1, H).

As shown FIG. 18B, if the right reference sample and the bottomreference sample are generated, a first prediction sample P_(h)(x, y)and a second prediction sample P_(v)(x, y) for the prediction targetblock may be generated based on the generated reference samples. At thistime, the first prediction sample P_(h)(x, y) may be generated based ona weighted sum of the left reference sample P(−1, y) and the rightreference sample P(W, y) and the second prediction sample may begenerated based on a weighted sum of the top reference sample P(x, −1)and the bottom reference sample P(x, H).

Positions of reference samples used to generate the first predictionimage and the second prediction image may vary depending on a size or ashape of the current block. That is, positions of the top referencesample or the left reference sample used to derive the right referencesample or the bottom reference sample may vary depending on the size orthe shape of the current block.

For example, if the current block is a square block of N×N size, theright reference sample may be derived from P (N, −1) and the bottomreference sample may be derived from P(−1, N). Alternatively, the rightreference sample and the bottom reference sample may be derived based onat least one of a weighted sum, an average value, a minimum value, or amaximum value of P(N, −1) and P (−1, N). On the other hand, if thecurrent block is a non-square block, positions of the reference samplesused to derive the right reference sample and the bottom referencesamples may be determined differently, depending on the shape of thecurrent block.

FIGS. 19 and 20 are diagrams for explaining determination of a rightreference sample and a bottom reference sample for a non-square block,according to an embodiment of the present invention.

As in the example shown in FIG. 19, when the current block is anon-square block of (N/2)×N size, a right reference sample is derivedbased on a top reference sample P(N/2, −1), and a bottom referencesample is derived based on a left reference sample P(−1, N).

Alternatively, the right reference sample or the bottom reference samplemay be derived based on at least one of a weighted sum, an averagevalue, a minimum value, or a maximum value of the top reference sampleP(N/2, −1) and the left reference sample P(−1, N). For example, theright reference sample may be derived as a weighted sum or an average ofP(N/2, −1) and P (−1, N), or may be derived as a weighted sum or anaverage of the above calculated value and the top reference sample.Alternatively, the bottom reference sample may be derived as a weightedsum or an average of P(N/2, −1) and P(−1, N), or may be derived as aweighted sum or an average of the above calculated value and the leftreference sample.

On the other hand, as in the example shown in FIG. 20, if the currentblock is a non-square block of N×(N/2) size, the right reference samplemay be derived based on the top reference sample P(N, −1) and the bottomreference sample may be derived based on the left reference sample P(−1,N/2).

Alternatively, it is also possible to derive the right reference sampleor the bottom reference sample based on at least one of a weighted sum,an average value, a minimum value, or a maximum value of the topreference sample P(N, −1) and the left reference sample P(−1, N/2). Forexample, the right reference sample may be derived as a weighted sum oran average of P(N, −1) and P(−1, N/2), or may be derived as a weightedsum or an average of the above calculated value and the top referencesample. Alternatively, the bottom reference sample may be derived as aweighted sum or an average of P(N, −1) and P(−1, N/2), or may be derivedas a weighted sum or an average of the above calculated value and theleft reference sample.

Namely, the bottom reference sample may be derived based on at least oneof the bottom left reference sample of the current block located on thesame horizontal line as the bottom reference sample or the top rightreference sample of the current block located on the same vertical lineas the right reference sample, and the right reference sample may bederived based on at least one of the top right reference sample of thecurrent block located on the same vertical line as the right referencesample or the bottom left reference sample of the current block locatedon the same horizontal line as the bottom reference sample.

The first prediction image may be calculated based on a weightedprediction of reference samples located on the same horizontal line asthe prediction target sample. In addition, the second prediction imagemay be calculated based on a weighted prediction of reference sampleslocated on the same vertical line as the prediction target sample.

Alternatively, it is also possible to generate the first predictionimage or the second prediction image based on an average value, aminimum value or a maximum value of reference samples.

A method of deriving a reference sample or a method of deriving thefirst prediction image or the second prediction image may be setdifferently depending on whether the prediction target sample isincluded in a predetermined area in the current block, a size or a shapeof the current block. Specifically, depending on the position of theprediction target sample, the number or positions of reference samplesused to derive the right or bottom reference sample may be determineddifferently, or depending on the position of the prediction targetsample, the weight or the number of reference samples used to derive thefirst prediction image or the second prediction image may be setdifferently.

For example, a right reference sample used to derive first predictionimage of prediction target samples included in the predetermined regionmay be derived using only the top reference sample, and a rightreference sample used to derive the first prediction image of predictiontarget samples outside of the predetermined region may be derived basedon a weighted sum or an average of a top reference sample and a leftreference sample.

For example, as in the example shown in FIG. 19, when the current blockis a non-square block whose height is longer than a width, the rightreference sample of the prediction target sample located at (x, y) andincluded in the predetermined region of the current block may be derivedfrom P(N/2, −1). On the other hand, the right reference sample of theprediction target sample located at (x′, y′) and outside of thepredetermined region in the current block may be derived based on aweighted sum or an average value of P(N/2, −1) and P(−1, N).

Alternatively, as in the example shown in FIG. 20, when the currentblock is a non-square block whose width is greater than a height, abottom reference sample of the prediction target sample located at (x,y) and included in the predetermined region in the current block may bederived based on P(−1, N/2). On the other hand, a bottom referencesample of the prediction target sample located at (x′, y′) and outsideof the predetermined region in the current block may be derived based ona weighted sum or an average value of P(N, −1) and P(−1, N/2).

For example, the first prediction image or the second prediction imagefor the prediction target samples included in the predetermined regionmay be generated based on the weighted sum of reference samples. On theother hand, the first prediction image or the second prediction imagefor the prediction target samples outside the predetermined region maybe generated by an average value, a minimum value, or a maximum value ofreference samples or may be generated by using only one of referencesamples located at a predetermined position. For example, as shown in anexample in FIG. 19, if the current block is a non-square block whoseheight is longer than a width, the first prediction image for theprediction target sample located at (x, y) and included in thepredetermined region may be generated by using only one of a rightreference sample P(N/2, y) derived from P(N/2, −1) or a left referencesample located at P(−1, y). On the other hand, the first predictionimage for the prediction target sample located at (x′, y′) and outsideof the predetermined region may be generated based on a weighted sum oran average of a right reference sample P(N/2, y′) derived from P(N/2,−1) and a reference sample located at P(−1, y′).

Alternatively, as in an example shown in FIG. 20, if the current blockis a non-square block whose width is greater than a height, the secondprediction image for the prediction target sample located at (x, y) andincluded in the predetermined region of the current block may begenerated by using only one of a bottom reference sample P(x, N/2)derived from P(−1, N/2) or a top reference sample located at P(x, −1).On the other hand, the second prediction image for the prediction targetsample located at (x′, y′) and does not included in the predeterminedregion may be generated based on a weighted sum or an average of abottom reference sample P(x′, N/2) derived from P(−1, N/2) and areference sample located at P(−1, y′).

In the above-described embodiment, the predetermined region or an outerregion of the predetermined region may include a remaining regionexcluding samples located at a boundary of the current block. Theboundary of the current block may include at least one of a leftboundary, a right boundary, a top boundary, or a bottom boundary. Inaddition, the number or position of boundaries included in thepredetermined region or the outer region of the predetermined region maybe set differently according to a shape of the current block.

Under planar mode, the final prediction image may be derived based on aweighted sum, an average value, a minimum value, or a maximum value ofthe first prediction image and the second prediction image.

For example, the following Equation 9 shows an example of generating thefinal prediction image P based on the weighted sum of the firstprediction image P_(h) and the second prediction image P_(v).

P(x,y)=(w*P _(h)(x,y)+(1−w)*P _(v)(x,y)+N)>>(log 2(N)+1)  [Equation 9]

In Equation 9, the prediction weight w may be different according to ashape or a size of the current block, or a position of the predictiontarget sample.

For example, the prediction weight w may be derived in consideration ofa width of the current block, a height of the current block, or a ratiobetween the width and the height. If the current block is a non-squareblock whose width is greater than the height, w may be set so that moreweight is given to the first prediction image. On the other hand, if thecurrent block is a non-square block whose height is greater than thewidth, w may be set so that more weight is given to the secondprediction image.

For example, when the current block has a square shape, the predictionweight w may have a value of ½. On the other hand, if the current blockis a non-square block whose height is greater than the width (e.g.,(N/2)×N), the prediction weight w may be set to ¼, and if the currentblock is a non-square block whose width is greater than the height(e.g., N×(N/2)), the prediction weight w may be set to ¾.

When an intra prediction mode of a current block is a directionalprediction mode, intra prediction of the current block may be performedbased on a directionality of the directional prediction mode. Forexample, Table 3 shows intra direction parameters (intraPredAng) of Mode2 to Mode 34, which are directional intra prediction modes shown in FIG.8.

TABLE 3 Pred Mode Intra 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Intra —32 26 21 17 13 9 5 2 0 −2 −5 −9 −13 −17 −21 Pred Ang Pred Mode Intra 1819 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Intra −32 −26 −21 −17 −13−9 −5 −2 0 2 5 9 13 17 21 26 Pred Ang

In Table 3, although 33 directional intra prediction modes areexemplified, it is also possible that more or fewer directional intraprediction modes are defined.

Based on a lookup table defining a mapping relationship between adirectional intra prediction mode and an intra direction parameter, anintra direction parameter for the current block may be determined.Alternatively, an intra direction parameter for the current block may bedetermined based on information signaled through a bitstream.

Intra prediction of the current block may be performed using at leastone of a left reference sample or a top reference sample, depending onthe directionality of the directional intra prediction mode. Here, thetop reference sample means a reference sample (e.g., (−1, −1) to (2W−1,−1)) having a y-axis coordinate smaller than a prediction sample (x, 0)included in the top most row in the current block and the left referencesample means a reference sample (e.g., (−1, −1) to (−1, 2H−1)) having anx-axis coordinate smaller than a prediction sample (0, y) included in aleft most column in the current block.

It is possible to arrange reference samples of the current block in onedimension according to the directionality of the intra prediction mode.Specifically, when both the top reference sample and the left referencesample are to be used in the intra prediction of the current block, itis possible to select reference samples for each prediction targetsample, assuming that they are arranged in a line in a verticaldirection or a horizontal direction.

For example, when the intra direction parameter is negative (forexample, in the case of intra prediction modes corresponding to Mode 11to Mode 25 in Table 3), a one-dimensional reference sample group(P_ref_1D) may be constructed by rearranging top reference samples andleft reference samples in the horizontal direction or the verticaldirection.

FIGS. 21 and 22 are diagrams illustrating a one-dimensional referencesample group in which reference samples are rearranged in a line.

Whether the reference samples are rearranged in the vertical directionor in the horizontal direction may be determined according to thedirectionality of the intra prediction mode. For example, as in theexample shown in FIG. 21, if the intra prediction mode index is in 11 to18, the top reference samples of the current block are rotatedcounterclockwise so that the one-dimensional reference sample group isgenerated which the left reference samples and the top reference samplesare arranged in the vertical direction.

On the other hand, as in the example shown in FIG. 22, when the intraprediction mode index is in 19 to 25, the left reference samples of thecurrent block are rotated clockwise so that the one-dimensionalreference sample group is generated which the left reference samples andthe top reference samples are arranged in the horizontal direction.

If the intra direction parameter of the current block is not negative,intra prediction for the current block may be performed using only theleft reference samples or the top reference samples. Thereby, theone-dimensional reference sample group for intra prediction modes whoseintra direction parameters are not negative may be generated by usingonly the left reference samples or the top reference samples.

Based on the intra direction parameter, a reference sample determinationindex iIdx may be derived for specifying at least one reference sampleused to predict the prediction target sample. In addition, aweight-related parameter i_(fact), which is used to determine weightsapplied to each reference sample, may be derived based on the intradirection parameter. For example, the following Equations 10 and 11 showexamples of deriving the reference sample determination index and theweight-related parameter.

iIdx=(y+1)*(P _(ang)/32)

iIdx=[(y+1)*(P _(ang)]31  [Equation 10]

Based on the reference sample determination index, at least onereference sample may be specified for each prediction target sample. Forexample, based on the reference sample determination index, a positionof a reference sample in the one-dimensional reference sample group forpredicting the prediction target sample in the current block may bespecified. Based on the reference sample at the specified position, aprediction image (i.e., a prediction sample) for the prediction targetsample may be generated.

A plurality of intra prediction modes may be used to perform intraprediction for the current block. For example, different intraprediction modes or different directional intra prediction modes may beapplied to each of prediction target samples in the current block.Alternatively, different intra prediction modes or different directionalintra prediction modes may be applied to each of predetermined samplegroups in the current block. Here, the predetermined sample group mayrepresent a sub-block having a predetermined size/shape, a blockincluding a predetermined number of prediction target samples, or apredetermined area. The number of sample groups may be variablydetermined according to a size/shape of the current block, the number ofprediction target samples included in the current block, the intraprediction mode of the current block, or the like, or may have a fixednumber predefined in the encoder and the decoder. Alternatively, it isalso possible to signal the number of sample groups included in thecurrent block through the bitstream.

A plurality of intra prediction modes for the current block may berepresented by a combination of the plurality of intra prediction modes.For example, the plurality of intra prediction modes may be representedby a combination of a plurality of non-directional intra predictionmodes, a combination of a directional prediction mode and anon-directional intra prediction mode, or a combination of a pluralityof directional intra prediction modes. Alternatively, the intraprediction mode may be encoded/decoded for each unit to which differentintra prediction modes are applied.

When the intra-prediction mode of the current block is considered, if itis determined that the prediction target sample cannot be predicted byonly one reference sample, prediction of the prediction target samplemay be performed using a plurality of reference samples. Specifically,in accordance with the intra prediction mode of the current block, it ispossible to perform prediction on the prediction target sample byinterpolating a reference sample at a predetermined position and aneighboring reference sample neighboring the reference sample at thepredetermined position.

For example, when an imaginary angular line following a slope of theintra prediction mode or an angle of the intra prediction mode does notpass an integer pel (i.e., a reference sample at an integer position) inthe one-dimensional reference sample group, a prediction image for theprediction target sample may be generated by interpolating a referencesample positioned on the angular line and a reference sample adjacent toa left/right or top/bottom side of the reference sample. For example,the following Equation 11 shows an example of interpolating two or morereference samples to generate a prediction sample P (x, y) for theprediction target sample.

P(x,y)=(32−i _(fact))/32*P_ref_1D(x+iIdx+1)+i_(fact)/32*P_ref_1D(x+iIdx+2)  [Equation 11]

Coefficients of an interpolation filter may be determined based on theweight-related parameter i_(fact). For example, the coefficients of theinterpolation filter may be determined based on a distance between afractional pel located on the angular line and an integer pel (i.e., aninteger position of each reference sample).

When the intra prediction mode of the current block is considered, ifthe prediction target sample can be predicted by only one referencesample, a prediction image for the prediction target sample may begenerated based on a reference sample specified by the intra predictionmode of the current block.

For example, an imaginary angular line following a slope of the intraprediction mode or an angle of the intra prediction mode passes aninteger pel (i.e., a reference sample at an integer position) in theone-dimensional reference sample group, a prediction image for theprediction target sample may be generated by copying a reference sampleat the integer pel or by considering a distance between a referencesample at the integer pel and the prediction target sample. For example,the following Equation 12 is an example of generating a prediction imageP(x,y) for the prediction target sample by copying a reference sampleP_ref_1D(x+iIdx+1) in the one-dimensional sample group specified by theintra prediction mode of the current block.

P(x,y)=P_ref_1D(x+iIdx+1)  [Equation 12]

For convenience of explanation, in the embodiments described later, areference sample specified by the intra prediction mode of the currentblock or an one-dimensional reference sample specified by the intraprediction mode of the current block will be referred to as a firstreference sample. For example, in a planar mode, reference samples usedto obtain a horizontal prediction image or a vertical prediction imageof the prediction target sample may be referred to as first referencesamples, and in a directional intra prediction mode, a reference sampleof the prediction target sample specified by the directionality of theintra prediction mode may be referred to as a first prediction referencesample. In addition, a prediction sample generated by predicting theprediction target sample based on the first reference sample will bereferred to as a first prediction image (or a first prediction sample),and intra prediction using the first reference sample will be referredto as a first intra prediction.

According to the present invention, in order to increase the efficiencyof intra prediction, it is possible to obtain a second prediction image(or a second prediction sample) for the prediction target sample byusing a second reference sample at a predetermined position.Specifically, the second prediction sample for the prediction targetsample may be generated by weight-prediction of the first predictionimage generated as a result of the first intra prediction and the secondreference sample at the predetermined position.

Whether or not to generate the second prediction sample may bedetermined based on a size of the current block, a shape of the currentblock, an intra prediction mode of the current block (for example,whether it is a directional intra prediction mode), a direction of theintra prediction mode, a distance between the prediction target sampleand the first reference sample and the like. Here, the distance betweenthe first reference sample and the prediction target sample may becalculated based on a distance of x-axis between the first referencesample and the prediction target sample and a distance of y-axis betweenthe first reference sample and the prediction target sample.

FIG. 23 is a diagram for explaining a distance between a first referencesample and a prediction target sample. In FIG. 23, it is exemplifiedthat a distance between the first reference sample and the predictiontarget sample is calculated by summing an absolute value of anx-coordinate difference between the first reference sample and theprediction target sample and an absolute value of a y-coordinatedifference between the first reference sample and the prediction targetsample.

As an example, it is possible to compare a distance between theprediction target sample and the first reference sample with a thresholdvalue, and then determine whether to generate a second prediction imageaccording to the result of the comparison. The threshold value may bedetermined depending on a width, height, intra prediction mode (forexample, whether it is a directional intra-prediction mode) of theprediction block or a slope of the intra prediction mode.

The first reference sample used in the first intra prediction can be setas the second reference sample. For example, if a plurality of referencesamples are used in the first intra prediction, any one of the pluralityof reference samples may be set as the second reference sample.

Alternatively, a reference sample located at a position different fromthe first reference sample may be set as the second reference sample. Atthis time, the first reference sample and the second reference samplemay be adjacent to the same boundary of the current block, or may beadjacent to different boundaries of the current block. For example, boththe first reference sample and the second reference sample may be topreference samples of the current block or left reference samples of thecurrent block, or either the first reference sample or the secondreference sample is the top reference sample while the other is the leftreference sample.

FIGS. 24 and 25 are diagrams showing positions of a first referencesample and a second reference sample.

FIG. 24 shows an example in which the first reference sample and thesecond reference sample are adjacent to the same boundary of the currentblock, and FIG. 25 shows an example in which each of the first referencesample and the second reference sample are adjacent to differentboundaries of the current block.

Specifically, it is depicted in FIG. 24 that both the first referencesample and the second reference sample are the top reference samples ofthe current block, and it is depicted in FIG. 25 that the firstreference sample of the current block is the top reference sample whilethe second reference sample is the left reference sample of the currentblock.

The second reference sample may include a reference sample closest tothe prediction target sample. Here, the reference sample closest to theprediction target sample may include at least one of a reference samplelying on the same horizontal line as the prediction target sample or areference sample lying on the same vertical line as the predictiontarget sample.

Alternatively, a reference sample neighboring to the first referencesample may be determined as the second reference sample.

As another example, the second reference sample may be determined basedon the directionality of the intra prediction mode of the current block.For example, the second reference sample may be specified by animaginary angular line following the slope of the intra-prediction modeof the current block. For example, when the angular line is extended toboth sides, the reference sample located on one side of the angular linemay be set as the first reference sample, and the reference samplelocated on the other side of the angular line may be set as the secondreference sample.

FIG. 26 is a diagram showing positions of a first reference sample and asecond reference sample. If it is assumed that that the intra predictionmode of the current block is a left-bottom diagonal direction (forexample, Mode shown in FIG. 8) or a top-right diagonal direction (forexample, Mode 34 shown in FIG. 8), when the angular line defined by theintra prediction mode is extended to both sides from the predictiontarget sample, reference samples located at positions passing throughthe angular line may be set as the first reference sample and the secondreference sample. For example, when the intra prediction mode of thecurrent block is the top-right diagonal direction, a reference samplelocated at a position of r(x+y+2, −1) is determined as the firstreference sample and a reference a reference sample located at aposition of r(−1, x+y+2) is determined as the second reference samplefor the prediction target sample located at (2, 2). On the other hand,when the intra prediction mode of the current block is the left-bottomdiagonal direction, a reference sample located at a position of r (−1,x+y+2) is determined as the first reference sample and a referencesample located at a position of r (x+y+2, −1) is determined as thesecond reference sample for the prediction target sample located at (2,2).

Alternatively, a reference sample at a predefined location may be set asthe second reference sample. For example, a reference sample adjacent toa top-left corner of the current block, a reference sample adjacent to atop-right corner of the current block, or a reference sample adjacent toa left-bottom corner of the current block may be set as the secondreference sample.

A plurality of reference samples may be selected as the second referencesample. For example, a plurality of reference samples satisfying acondition described above may be selected as the second referencesamples for second intra prediction

The second prediction image may be generated by weighted sum of thefirst prediction image and the second reference sample. For example, thefollowing Equation 13 represents an example of generating a secondprediction image P′(x, y) for a prediction target sample (x, y) througha weighted sum of a second reference sample P_ref_2nd and a firstprediction image P(x, y).

P′(x,y)=(1−w)*P_ref_2nd+w*P(x,y)[Equation 13]

Since the first prediction image is generated by copying the firstreference sample or interpolating a plurality of the first referencesamples, it can be understood that the second prediction image isgenerated through a weighted sum of the first reference sample P_ref_1stand the second reference sample P_ref_2nd.

Weights assigned to each of the first prediction image and the secondreference sample may be determined based on at least one of a size ofthe current block, a shape of the current block, an intra predictionmode of the current block, a position of the prediction target sample, aposition of the first reference sample or a position of the secondreference sample. For example, the weights assigned to each of the firstprediction image and the second reference image may be determined basedon a distance between the prediction target sample and the firstreference sample or a distance between the prediction target sample andthe second reference sample.

For example, when the distance between the prediction target sample andthe first reference sample is f1 and the distance between the predictiontarget sample and the reference sample is f2, a weighted predictionparameter w may be set as f2/f1, f1/f2, f2/(f1+f2), or f2/(f1+f2).

The final prediction image of the prediction target sample may bedetermined as the first prediction image or the second prediction image.At this time, whether to determine the first prediction image as thefinal prediction image or whether to determine the second predictionimage as the final prediction image may be determined according to asize of the current block, a shape of the current block, an intraprediction mode of the current block, position of the prediction targetsample, or the like. For example, the final prediction image of theprediction target samples included in a first area in the current blockis determined as the first prediction image, while the final predictionimage of the prediction target samples included in a second area, whichis different from the first area, is determined as the second predictionimage.

FIG. 27 is a flowchart illustrating processes of obtaining a residualsample according to an embodiment to which the present invention isapplied.

First, a residual coefficient of a current block may be obtained S2710.A decoder may obtain a residual coefficient through a coefficientscanning method. For example, the decoder may perform a coefficient scanusing a diagonal scan, a jig-zag scan, an up-right scan, a verticalscan, or a horizontal scan, and may obtain residual coefficients in aform of a two-dimensional block.

An inverse quantization may be performed on the residual coefficient ofthe current block S2720.

It is possible to determine whether to skip an inverse transform on thedequantized residual coefficient of the current block S2730.Specifically, the decoder may determine whether to skip the inversetransform on at least one of a horizontal direction or a verticaldirection of the current block. When it is determined to apply theinverse transform on at least one of the horizontal direction or thevertical direction of the current block, a residual sample of thecurrent block may be obtained by inverse transforming the dequantizedresidual coefficient of the current block S2740. Here, the inversetransform can be performed using at least one of DCT, DST, and KLT.

When the inverse transform is skipped in both the horizontal directionand the vertical direction of the current block, inverse transform isnot performed in the horizontal direction and the vertical direction ofthe current block. In this case, the residual sample of the currentblock may be obtained by scaling the dequantized residual coefficientwith a predetermined value S2750.

Skipping the inverse transform on the horizontal direction means thatthe inverse transform is not performed on the horizontal direction butthe inverse transform is performed on the vertical direction. At thistime, scaling may be performed in the horizontal direction.

Skipping the inverse transform on the vertical direction means that theinverse transform is not performed on the vertical direction but theinverse transform is performed on the horizontal direction. At thistime, scaling may be performed in the vertical direction.

It may be determined whether or not an inverse transform skip techniquemay be used for the current block depending on a partition type of thecurrent block. For example, if the current block is generated through abinary tree-based partitioning, the inverse transform skip scheme may berestricted for the current block. Accordingly, when the current block isgenerated through the binary tree-based partitioning, the residualsample of the current block may be obtained by inverse transforming thecurrent block. In addition, when the current block is generated throughbinary tree-based partitioning, encoding/decoding of informationindicating whether or not the inverse transform is skipped (e.g.,transform_skip_flag) may be omitted.

Alternatively, when the current block is generated through binarytree-based partitioning, it is possible to limit the inverse transformskip scheme to at least one of the horizontal direction or the verticaldirection. Here, the direction in which the inverse transform skipscheme is limited may be determined based on information decoded fromthe bitstream, or may be adaptively determined based on at least one ofa size of the current block, a shape of the current block, or an intraprediction mode of the current block.

For example, when the current block is a non-square block having a widthgreater than a height, the inverse transform skip scheme may be allowedonly in the vertical direction and restricted in the horizontaldirection. That is, when the current block is 2N×N, the inversetransform is performed in the horizontal direction of the current block,and the inverse transform may be selectively performed in the verticaldirection.

On the other hand, when the current block is a non-square block having aheight greater than a width, the inverse transform skip scheme may beallowed only in the horizontal direction and restricted in the verticaldirection. That is, when the current block is N×2N, the inversetransform is performed in the vertical direction of the current block,and the inverse transform may be selectively performed in the horizontaldirection.

In contrast to the above example, when the current block is a non-squareblock having a width greater than a height, the inverse transform skipscheme may be allowed only in the horizontal direction, and when thecurrent block is a non-square block having a height greater than awidth, the inverse transform skip scheme may be allowed only in thevertical direction.

Information indicating whether or not to skip the inverse transform withrespect to the horizontal direction or information indicating whether toskip the inverse transformation with respect to the vertical directionmay be signaled through a bitstream. For example, the informationindicating whether or not to skip the inverse transform on thehorizontal direction is a 1-bit flag, ‘hor_transform_skip_flag’, andinformation indicating whether to skip the inverse transform on thevertical direction is a 1-bit flag, ‘ver_transform_skip_flag’. Theencoder may encode at least one of ‘hor_transform_skip_flag’ or‘ver_transform_skip_flag’ according to the shape of the current block.Further, the decoder may determine whether or not the inverse transformon the horizontal direction or on the vertical direction is skipped byusing at least one of “hor_transform_skip_flag” or“ver_transform_skip_flag”.

It may be set to skip the inverse transform for any one direction of thecurrent block depending on a partition type of the current block. Forexample, if the current block is generated through a binary tree-basedpartitioning, the inverse transform on the horizontal direction orvertical direction may be skipped. That is, if the current block isgenerated by binary tree-based partitioning, it may be determined thatthe inverse transform for the current block is skipped on at least oneof a horizontal direction or a vertical direction withoutencoding/decoding information (e.g., transform_skip_flag,hor_transform_skip_flag, ver_transform_skip_flag) indicating whether ornot the inverse transform of the current block is skipped.

Although the above-described embodiments have been described on thebasis of a series of steps or flowcharts, they do not limit thetime-series order of the invention, and may be performed simultaneouslyor in different orders as necessary. Further, each of the components(for example, units, modules, etc.) constituting the block diagram inthe above-described embodiments may be implemented by a hardware deviceor software, and a plurality of components. Or a plurality of componentsmay be combined and implemented by a single hardware device or software.The above-described embodiments may be implemented in the form ofprogram instructions that may be executed through various computercomponents and recorded in a computer-readable recording medium. Thecomputer-readable recording medium may include one of or combination ofprogram commands, data files, data structures, and the like. Examples ofcomputer-readable media include magnetic media such as hard disks,floppy disks and magnetic tape, optical recording media such as CD-ROMsand DVDs, magneto-optical media such as floptical disks, media, andhardware devices specifically configured to store and execute programinstructions such as ROM, RAM, flash memory, and the like. The hardwaredevice may be configured to operate as one or more software modules forperforming the process according to the present invention, and viceversa.

INDUSTRIAL APPLICABILITY

The present invention may be applied to electronic devices which is ableto encode/decode a video.

1-15. (canceled)
 16. A method of decoding a video, the methodcomprising: determining an intra prediction mode of a current block;obtaining a prediction sample at a target position based on the intraprediction mode and a first reference sample; determining whether tomodify the prediction sample or not; and obtaining a reconstructionsample based on the prediction sample or a modified prediction sample,wherein determination of whether the prediction sample is modified ornot is based on a size and the intra prediction mode of the currentblock, wherein when it is determined to modify the prediction sample,the prediction sample is modified by using a second reference sample,wherein the second reference sample is determined based on a predictionangle of the intra prediction mode when the intra prediction mode is adirectional mode, and wherein when the intra prediction mode is atop-right diagonal directional mode, the second reference samplecomprises a left reference sample lying on a bottom-left diagonaldirection from the target position.
 17. The method of claim 16, whereinwhen the intra prediction mode is not the directional mode, at least oneof a horizontal reference sample or a vertical reference sample isdetermined as the second reference sample, the horizontal referencesample lying on a same horizontal line as the target position, thevertical reference sample lying on a same vertical line as the targetposition.
 18. The method of claim 16, wherein the modified predictionsample is obtained based on a weighted sum of the prediction sample andthe second reference sample.
 19. The method of claim 18, wherein weightsapplied to each of the prediction sample and the second reference sampleare determined based on a coordinate of the target position.
 20. Amethod of encoding a video, the method comprising: determining an intraprediction mode of a current block; obtaining a prediction sample at atarget position based on the intra prediction mode and a first referencesample; determining whether to modify the prediction sample or not; andobtaining a residual sample by subtracting the prediction sample or amodified prediction sample from an original sample, whereindetermination of whether the prediction sample is modified or not isbased on a size and the intra prediction mode of the current block,wherein when it is determined to modify the prediction sample, theprediction sample is modified by using a second reference sample,wherein the second reference sample is determined based on a predictionangle of the intra prediction mode when the intra prediction mode is adirectional mode, and wherein when the intra prediction mode is atop-right diagonal direction, the second reference sample comprises aleft reference sample lying on a bottom-left diagonal direction from thetarget position.
 21. The method of claim 20, wherein when the intraprediction mode is not the directional mode, at least one of ahorizontal reference sample or a vertical reference sample is determinedas the second reference sample, the horizontal reference sample lying ona same horizontal line as the target position, the vertical referencesample lying on a same vertical line as the target position.
 22. Themethod of claim 20, wherein the modified prediction sample is obtainedbased on a weighted sum of the prediction sample and the secondreference sample.
 23. The method of claim 22, wherein weights applied toeach of the prediction sample and the second reference sample aredetermined based on a coordinate of the target position.
 24. Anon-transitory computer-readable medium for storing data associated witha video signal, comprising: a data stream stored in the non-transitorycomputer-readable medium, the data stream being encoded by an encodingmethod which comprising: determining an intra prediction mode of acurrent block; obtaining a prediction sample at a target position basedon the intra prediction mode and a first reference sample; determiningwhether to modify the prediction sample or not; and obtaining a residualsample by subtracting the prediction sample or a modified predictionsample from an original sample, wherein determination of whether theprediction sample is modified or not is based on a size and the intraprediction mode of the current block, wherein when it is determined tomodify the prediction sample, the prediction sample is modified by usinga second reference sample, wherein the second reference sample isdetermined based on a prediction angle of the intra prediction mode whenthe intra prediction mode is a directional mode, and wherein when theintra prediction mode is a top-right diagonal direction, the secondreference sample comprises a left reference sample lying on abottom-left diagonal direction from the target position.